package 剑指Offer2;

import java.util.HashMap;

public class _16不含重复字符的最长子字符串 {
    private HashMap<Character,Integer> window = new HashMap<>();
    public int lengthOfLongestSubstring(String s) {
        if(s == null || s.length() == 0) return 0;
        int right = 0,left = 0,res = 0;
        while(right<s.length()){
            char c = s.charAt(right);
            right++;
            window.put(c,window.getOrDefault(c,0)+1);

            while(window.get(c)>1){
                char d = s.charAt(left);
                left++;
                if(window.containsKey(d)){
                    window.put(d,window.getOrDefault(d,0)-1);
                }
            }
            //去除重复以后计算最大不重复子串的长度
            res = Math.max(res,right - left);
        }
    return res;
    }
}
